package indi.zhang.ttl.core;

import indi.zhang.ttl.tools.TTLUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Map;


@Aspect
@Component
@RequiredArgsConstructor
@Slf4j
public class AsyncAop {

    private final TTLUtils ttlUtils;

    @Pointcut("@annotation(indi.zhang.ttl.core.ZhangAsync)")
    public void costTimePointCut() {
        log.info("costTimePointCut");
    }

    @Around("costTimePointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        ttlUtils.aysnc(() -> {
            try {
                point.proceed();
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
        });
        return null;
    }
}
